using System;
using System.Data;
using System.Data.SqlTypes;
using System.Data.SqlClient;

namespace DataEntity
{
	public class T_Project_SalseAgency_Exchange : DBInteractionBase
	{
		#region Class Member Declarations
        private SqlString _project_SalseAgency_Exchange_FirstA2, _project_SalseAgency_Exchange_FirstA1;
			private SqlGuid			_project_SalseAgency_Exchange_SalseAgencyMainID, _project_SalseAgency_Exchange_ID, _project_SalseAgency_Exchange_MainID;
		#endregion





	


		public override bool Update()
		{
			SqlCommand	cmdToExecute = new SqlCommand();
			cmdToExecute.CommandText = "dbo.[sp_t_Project_SalseAgency_Exchange_Update]";
			cmdToExecute.CommandType = CommandType.StoredProcedure;

			// Use base class' connection object
			cmdToExecute.Connection = _mainConnection;

			try
			{
				cmdToExecute.Parameters.Add(new SqlParameter("@guidProject_SalseAgency_Exchange_ID", SqlDbType.UniqueIdentifier, 16, ParameterDirection.Input, false, 0, 0, "", DataRowVersion.Proposed, _project_SalseAgency_Exchange_ID));
				cmdToExecute.Parameters.Add(new SqlParameter("@guidProject_SalseAgency_Exchange_MainID", SqlDbType.UniqueIdentifier, 16, ParameterDirection.Input, false, 0, 0, "", DataRowVersion.Proposed, _project_SalseAgency_Exchange_MainID));
				cmdToExecute.Parameters.Add(new SqlParameter("@guidProject_SalseAgency_Exchange_SalseAgencyMainID", SqlDbType.UniqueIdentifier, 16, ParameterDirection.Input, false, 0, 0, "", DataRowVersion.Proposed, _project_SalseAgency_Exchange_SalseAgencyMainID));
                cmdToExecute.Parameters.Add(new SqlParameter("@iProject_SalseAgency_Exchange_FirstA1", SqlDbType.NVarChar, 20, ParameterDirection.Input, false, 10, 0, "", DataRowVersion.Proposed, _project_SalseAgency_Exchange_FirstA1));
				cmdToExecute.Parameters.Add(new SqlParameter("@sProject_SalseAgency_Exchange_FirstA2", SqlDbType.NVarChar, 20, ParameterDirection.Input, false, 0, 0, "", DataRowVersion.Proposed, _project_SalseAgency_Exchange_FirstA2));

				if(_mainConnectionIsCreatedLocal)
				{
					// Open connection.
					_mainConnection.Open();
				}
				else
				{
					if(_mainConnectionProvider.IsTransactionPending)
					{
						cmdToExecute.Transaction = _mainConnectionProvider.CurrentTransaction;
					}
				}

				// Execute query.
				_rowsAffected = cmdToExecute.ExecuteNonQuery();
				return true;
			}
			catch(Exception ex)
			{
				// some error occured. Bubble it to caller and encapsulate Exception object
				throw new Exception("T_Project_SalseAgency_Exchange::Update::Error occured.", ex);
			}
			finally
			{
				if(_mainConnectionIsCreatedLocal)
				{
					// Close connection.
					_mainConnection.Close();
				}
				cmdToExecute.Dispose();
			}
		}


		public override bool Delete()
		{
			SqlCommand	cmdToExecute = new SqlCommand();
			cmdToExecute.CommandText = "dbo.[sp_t_Project_SalseAgency_Exchange_Delete]";
			cmdToExecute.CommandType = CommandType.StoredProcedure;

			// Use base class' connection object
			cmdToExecute.Connection = _mainConnection;

			try
			{
				cmdToExecute.Parameters.Add(new SqlParameter("@guidProject_SalseAgency_Exchange_ID", SqlDbType.UniqueIdentifier, 16, ParameterDirection.Input, false, 0, 0, "", DataRowVersion.Proposed, _project_SalseAgency_Exchange_ID));

				if(_mainConnectionIsCreatedLocal)
				{
					// Open connection.
					_mainConnection.Open();
				}
				else
				{
					if(_mainConnectionProvider.IsTransactionPending)
					{
						cmdToExecute.Transaction = _mainConnectionProvider.CurrentTransaction;
					}
				}

				// Execute query.
				_rowsAffected = cmdToExecute.ExecuteNonQuery();
				return true;
			}
			catch(Exception ex)
			{
				// some error occured. Bubble it to caller and encapsulate Exception object
				throw new Exception("T_Project_SalseAgency_Exchange::Delete::Error occured.", ex);
			}
			finally
			{
				if(_mainConnectionIsCreatedLocal)
				{
					// Close connection.
					_mainConnection.Close();
				}
				cmdToExecute.Dispose();
			}
		}


		public override DataTable SelectOne()
		{
			SqlCommand	cmdToExecute = new SqlCommand();
			cmdToExecute.CommandText = "dbo.[sp_t_Project_SalseAgency_Exchange_SelectOne]";
			cmdToExecute.CommandType = CommandType.StoredProcedure;
			DataTable toReturn = new DataTable("t_Project_SalseAgency_Exchange");
			SqlDataAdapter adapter = new SqlDataAdapter(cmdToExecute);

			// Use base class' connection object
			cmdToExecute.Connection = _mainConnection;

			try
			{
				cmdToExecute.Parameters.Add(new SqlParameter("@guidProject_SalseAgency_Exchange_ID", SqlDbType.UniqueIdentifier, 16, ParameterDirection.Input, false, 0, 0, "", DataRowVersion.Proposed, _project_SalseAgency_Exchange_ID));

				if(_mainConnectionIsCreatedLocal)
				{
					// Open connection.
					_mainConnection.Open();
				}
				else
				{
					if(_mainConnectionProvider.IsTransactionPending)
					{
						cmdToExecute.Transaction = _mainConnectionProvider.CurrentTransaction;
					}
				}

				// Execute query.
				adapter.Fill(toReturn);
				if(toReturn.Rows.Count > 0)
				{
					_project_SalseAgency_Exchange_ID = (Guid)toReturn.Rows[0]["Project_SalseAgency_Exchange_ID"];
					_project_SalseAgency_Exchange_MainID = (Guid)toReturn.Rows[0]["Project_SalseAgency_Exchange_MainID"];
					_project_SalseAgency_Exchange_SalseAgencyMainID = (Guid)toReturn.Rows[0]["Project_SalseAgency_Exchange_SalseAgencyMainID"];
                    _project_SalseAgency_Exchange_FirstA1 = toReturn.Rows[0]["Project_SalseAgency_Exchange_FirstA1"] == System.DBNull.Value ? SqlString.Null : (string)toReturn.Rows[0]["Project_SalseAgency_Exchange_FirstA1"];
					_project_SalseAgency_Exchange_FirstA2 = toReturn.Rows[0]["Project_SalseAgency_Exchange_FirstA2"] == System.DBNull.Value ? SqlString.Null : (string)toReturn.Rows[0]["Project_SalseAgency_Exchange_FirstA2"];
				}
				return toReturn;
			}
			catch(Exception ex)
			{
				// some error occured. Bubble it to caller and encapsulate Exception object
				throw new Exception("T_Project_SalseAgency_Exchange::SelectOne::Error occured.", ex);
			}
			finally
			{
				if(_mainConnectionIsCreatedLocal)
				{
					// Close connection.
					_mainConnection.Close();
				}
				cmdToExecute.Dispose();
				adapter.Dispose();
			}
		}


		public override DataTable SelectAll()
		{
			SqlCommand	cmdToExecute = new SqlCommand();
			cmdToExecute.CommandText = "dbo.[sp_t_Project_SalseAgency_Exchange_SelectAll]";
			cmdToExecute.CommandType = CommandType.StoredProcedure;
			DataTable toReturn = new DataTable("t_Project_SalseAgency_Exchange");
			SqlDataAdapter adapter = new SqlDataAdapter(cmdToExecute);

			// Use base class' connection object
			cmdToExecute.Connection = _mainConnection;

			try
			{

				if(_mainConnectionIsCreatedLocal)
				{
					// Open connection.
					_mainConnection.Open();
				}
				else
				{
					if(_mainConnectionProvider.IsTransactionPending)
					{
						cmdToExecute.Transaction = _mainConnectionProvider.CurrentTransaction;
					}
				}

				// Execute query.
				adapter.Fill(toReturn);
				return toReturn;
			}
			catch(Exception ex)
			{
				// some error occured. Bubble it to caller and encapsulate Exception object
				throw new Exception("T_Project_SalseAgency_Exchange::SelectAll::Error occured.", ex);
			}
			finally
			{
				if(_mainConnectionIsCreatedLocal)
				{
					// Close connection.
					_mainConnection.Close();
				}
				cmdToExecute.Dispose();
				adapter.Dispose();
			}
		}


		#region Class Property Declarations
		public SqlGuid Project_SalseAgency_Exchange_ID
		{
			get
			{
				return _project_SalseAgency_Exchange_ID;
			}
			set
			{
				_project_SalseAgency_Exchange_ID = value;
			}
		}


		public SqlGuid Project_SalseAgency_Exchange_MainID
		{
			get
			{
				return _project_SalseAgency_Exchange_MainID;
			}
			set
			{
				SqlGuid project_SalseAgency_Exchange_MainIDTmp = (SqlGuid)value;
				if(project_SalseAgency_Exchange_MainIDTmp.IsNull)
				{
					throw new ArgumentOutOfRangeException("Project_SalseAgency_Exchange_MainID", "Project_SalseAgency_Exchange_MainID can't be NULL");
				}
				_project_SalseAgency_Exchange_MainID = value;
			}
		}


		public SqlGuid Project_SalseAgency_Exchange_SalseAgencyMainID
		{
			get
			{
				return _project_SalseAgency_Exchange_SalseAgencyMainID;
			}
			set
			{
				SqlGuid project_SalseAgency_Exchange_SalseAgencyMainIDTmp = (SqlGuid)value;
				if(project_SalseAgency_Exchange_SalseAgencyMainIDTmp.IsNull)
				{
					throw new ArgumentOutOfRangeException("Project_SalseAgency_Exchange_SalseAgencyMainID", "Project_SalseAgency_Exchange_SalseAgencyMainID can't be NULL");
				}
				_project_SalseAgency_Exchange_SalseAgencyMainID = value;
			}
		}


        public SqlString Project_SalseAgency_Exchange_FirstA1
		{
			get
			{
				return _project_SalseAgency_Exchange_FirstA1;
			}
			set
			{
                SqlString project_SalseAgency_Exchange_FirstA1Tmp = (SqlString)value;
				if(project_SalseAgency_Exchange_FirstA1Tmp.IsNull)
				{
					throw new ArgumentOutOfRangeException("Project_SalseAgency_Exchange_FirstA1", "Project_SalseAgency_Exchange_FirstA1 can't be NULL");
				}
				_project_SalseAgency_Exchange_FirstA1 = value;
			}
		}


		public SqlString Project_SalseAgency_Exchange_FirstA2
		{
			get
			{
				return _project_SalseAgency_Exchange_FirstA2;
			}
			set
			{
				SqlString project_SalseAgency_Exchange_FirstA2Tmp = (SqlString)value;
				if(project_SalseAgency_Exchange_FirstA2Tmp.IsNull)
				{
					throw new ArgumentOutOfRangeException("Project_SalseAgency_Exchange_FirstA2", "Project_SalseAgency_Exchange_FirstA2 can't be NULL");
				}
				_project_SalseAgency_Exchange_FirstA2 = value;
			}
		}
		#endregion
	}
}
